﻿// ParseLib - An open source library for natural language processing.
// Copyright (C) Kais Dukes, 2012. E-mail: kais@kaisdukes.com
// http://parselib.org

using System.IO;
using System.Xaml;
using log4net;
using ParseLib.Corpora;
using ParseLib.Text;

namespace ParseLib.Experiments
{
    public class Experiment
    {
        private static readonly ILog Log = LogManager.GetLogger(typeof (Experiment));

        public ICorpus Corpus { get; set; }

        public IModel Model { get; set; }

        public IEvaluationMethod Evaluation { get; set; }

        public static Experiment Read(Stream stream)
        {
            return (Experiment) XamlServices.Load(stream);
        }

        public void Run()
        {
            // Load the corpus.
            var corpusName = DisplayName.Of(Corpus);
            Log.DebugFormat("Loading {0}...", corpusName);
            Corpus.Load();
            Log.DebugFormat("{0}: {1} tokens.", corpusName, Corpus.TokenCount);
            
            // Run the experiment.
            Evaluation.Evaluate(Model, Corpus);
        }
    }
}